using System;
using System.Collections.Generic;
using System.Windows;
using WPFPractice.Utils;
using WPFPractice.ViewModels;
using WPFTemplateLib.Extensions;
using WPFTemplateLib.Models;

namespace WPFPractice.Windows
{
	/// <summary>
	/// WinTreeView.xaml 的交互逻辑
	/// </summary>
	public partial class WinTreeView : Window
	{
		public WinTreeView()
		{
			InitializeComponent();
			DataContext = new TreeViewViewModel();

		}
	}
}

namespace WPFPractice.ViewModels
{
	public class TreeViewViewModel : MyViewModelBase
	{
		#region 绑定

		/// <summary>
		/// 选择列表
		/// </summary>
		public List<CheckableTreeNode> TreeNodes { get; set; }

		#endregion

		#region 方法

		/// <inheritdoc />
		protected override void InitDataAfterConstruction()
		{
			Console.WriteLine("演示 TreeView 控件：");
			Console.WriteLine("1、演示 CheckableTreeNode");

			InitDataLocal();
		}

		private void InitDataLocal()
		{
			List<CheckableTreeNode> treeNodes = new();

			CheckableTreeNode n1Node = new("Node1") { Level = 1 };
			CheckableTreeNode n1C1Node = new("Node1Child1")
			{
				Children = new()
				{
					new ("Node1Child1-1"), new("Node1Child1-2"), new("Node1Child1-2"), new("Node1Child1-2")
				}
			};
			CheckableTreeNode n1C2Node = new("Node1Child2");
			CheckableTreeNode n1C3Node = new("Node1Child3");
			CheckableTreeNode n1C4Node = new("Node1Child4");
			CheckableTreeNode n1C5Node = new("Node1Child5");
			CheckableTreeNode n1C6Node = new("Node1Child6");
			n1Node.Children.AddRange(new List<CheckableTreeNode>() { n1C1Node, n1C2Node, n1C3Node, n1C4Node, n1C5Node, n1C6Node });

			CheckableTreeNode n2Node = new("Node2") { Level = 1 };

			CheckableTreeNode n3Node = new("Node3") { Level = 1 };
			CheckableTreeNode n3C1Node = new("Node3Child1")
			{
				Children = new()
				{
					new ("Node3Child1-1"), new("Node3Child1-2"), new("Node3Child1-2"), new("Node3Child1-2")
				}
			};
			CheckableTreeNode n3C2Node = new("Node3Child2");
			CheckableTreeNode n3C3Node = new("Node3Child3");
			CheckableTreeNode n3C4Node = new("Node3Child4");
			n3Node.Children.AddRange(new List<CheckableTreeNode>() { n3C1Node, n3C2Node, n3C3Node, n3C4Node });

			CheckableTreeNode n4Node = new("Node4") { Level = 1 };

			treeNodes.Add(n1Node);
			treeNodes.Add(n2Node);
			treeNodes.Add(n3Node);
			treeNodes.Add(n4Node);
			TreeNodes = treeNodes;
		}

		#endregion
	}
}

